package zhengqc.queue;

import zhengqc.list.List;

public abstract class AbstractDeque<E> implements Deque<E> {
    protected List<E> data;

    @Override /* 获取双端队列内元素数量 */
    public int getSize() {
        return data.getSize();
    }
    @Override /* 双端队列是否为空 */
    public boolean isEmpty() {
        return data.isEmpty();
    }
    @Override /* 从队首入队 */
    public void frontEnqueue(E element) {
        data.addFirst(element);
    }
    @Override /* 从队首出队 */
    public E frontDequeue() {
        if (this.isEmpty()) {
            throw new IllegalArgumentException("The Deque is empty!");
        }
        return data.removeFirst();
    }
    @Override /* 从队尾入队 */
    public void rearEnqueue(E element) {
        data.addLast(element);
    }
    @Override /* 从队尾出队 */
    public E rearDequeue() {
        if (this.isEmpty()) {
            throw new IllegalArgumentException("The Deque is empty!");
        }
        return data.removeLast();
    }
    @Override /* 查看队首元素 */
    public E getFront() {
        if (this.isEmpty()) {
            throw new IllegalArgumentException("The Deque is empty!");
        }
        return data.getFirst();
    }
    @Override /* 查看队尾元素 */
    public E getRear() {
        if (this.isEmpty()) {
            throw new IllegalArgumentException("The Deque is empty!");
        }
        return data.getLast();
    }
    @Override /* 清空双端队列 */
    public void clear() {
        data.clear();
    }
}
